package com.hmall.user.web.controller;


import com.hmall.domain.pojo.Address;
import com.hmall.user.service.IAddressService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.yaml.snakeyaml.events.Event;

import java.util.List;

/**
 * 用户地址实体类web层控制器
 *
 * @author xiaojiangshi
 */
@Slf4j
@RestController
@RequestMapping("/address")
public class AddressController {

    @Autowired
    private IAddressService addressService;

    /**
     * 根据地址id查询地址信息
     *
     * @param id 地址id
     * @return 地址类
     */
    @GetMapping("/{addressId}")
    public Address findAddressById(@PathVariable("addressId") Long id) {
        log.info("地址的id为：[{}]", id.toString());
        return addressService.getById(id);
    }

    /**
     * 根据用户id查询地址信息
     *
     * @param userId 用户id
     * @return 地址集
     */
    @GetMapping("/uid/{userId}")
    public List<Address> findAddressByUserId(@PathVariable("userId") Long userId) {
        log.info("用户id为：[{}]", userId.toString());
        return addressService.query().eq("user_id", userId).list();
    }
}
